package com.guomei.controller;

import com.guomei.bean.Feedback;
import com.guomei.service.FeedbackService;
import com.guomei.utils.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/api1/feedback")
@Slf4j
public class FeedbackController {
    @Autowired
    private FeedbackService feedbackService;

    /**
     * 提交反馈
     */
    @PostMapping("/submit")
    public Result<?> submitFeedback(@RequestBody Feedback feedback, HttpServletRequest request) {
        log.info("收到用户反馈提交请求: title={}", feedback.getTitle());
        return feedbackService.submitFeedback(feedback);
    }

    /**
     * 获取反馈详情
     */
    @GetMapping("/{feedbackId}")
    public Result<?> getFeedbackById(@PathVariable Long feedbackId) {
        log.info("查询反馈详情，反馈ID: {}", feedbackId);
        return feedbackService.getFeedbackById(feedbackId);
    }

    /**
     * 分页查询反馈列表
     */
    @GetMapping("/list")
    public Result<?> getFeedbackList(Feedback feedback,
                                     @RequestParam(defaultValue = "1") int pageNum,
                                     @RequestParam(defaultValue = "10") int pageSize) {
        log.info("查询反馈列表，页码: {}, 页面大小: {}", pageNum, pageSize);
        return feedbackService.getFeedbackList(feedback, pageNum, pageSize);
    }

    /**
     * 更新反馈处理状态
     */
    @PutMapping("/status")
    public Result<?> updateFeedbackStatus(@RequestBody Feedback feedback) {
        log.info("更新反馈状态，反馈ID: {}, 状态: {}", feedback.getFeedbackId(), feedback.getStatus());
        return feedbackService.updateFeedbackStatus(feedback);
    }

    /**
     * 删除反馈记录
     */
    @DeleteMapping("/{feedbackId}")
    public Result<?> deleteFeedback(@PathVariable Long feedbackId) {
        log.info("删除反馈记录，反馈ID: {}", feedbackId);
        return feedbackService.deleteFeedback(feedbackId);
    }

    /**
     * 获取反馈统计数据
     */
    @GetMapping("/statistics")
    public Result<?> getFeedbackStatistics() {
        log.info("获取反馈统计数据");
        return feedbackService.getFeedbackStatistics();
    }
}
